﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="NX5Web.admin.index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>后台管理</title>
    <link rel="shortcut icon" href="/images/logo.png" type="image/x-icon" />
    <link href="../Script/element-plus/index.css" rel="stylesheet" />
    <link href="../Script/xgplayer/xgplayer-3.0.10.min.css" rel="stylesheet" />
    <link href="../css/admin.css" rel="stylesheet" />

    <script src="../Script/vue.global.min.js"></script>
    <script src="../Script/jquery-3.7.1.min.js"></script>
    <script src="../Script/ktlapi.js"></script>
    <script src="../Script/lodash.min.js"></script> 
    <script src="../Script/element-plus/zh-cn.js"></script>
    <script src="../Script/element-plus/element-plus.js"></script>
    <script src="../Script/element-plus/index.iife.min.js"></script>
    <script src="../Script/echarts-5.4.3/dist/echarts.js"></script>
    <script src="../Script/sheetjs/xlsx.core.min.js"></script>
    <script src="../Script/crypto-js.min.js"></script>
    <script src="../Script/vue_components/ajax-component.js"></script>
    <script src="../Script/xgplayer/xgplayer-3.0.10.min.js"></script>

    <style>
        .msut :before{
            content: "*";
            color: #ff0000;
            margin-right: 4px;
        }

        .el-dropdown-link{ outline:none; }
    </style>
</head>
<body style="margin: 0px;padding: 0px;">
    <div id="mainApp" v-cloak="v-cloak">  
        <el-dialog v-model="dialogVisible" title="修改密码" width="300">
            <div>
                <el-form  ref="form" :model="form" :rules="rules" label-width="auto" style="max-width: 600px"> 
                    <el-form-item label="原密码" prop="old">
                        <el-input v-model="pwd.old"/>
                    </el-form-item>
                    <el-form-item label="新密码" prop="new">
                        <el-input v-model="pwd.new"/>
                    </el-form-item>
                    <el-form-item label="确 认" prop="newc">
                        <el-input v-model="pwd.newc"/>
                    </el-form-item>  
                </el-form>
            </div>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="dialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="cgpwd()">确 定</el-button>
                </div>
            </template>
        </el-dialog>
        <div style="position:relative">
            <div style="position: absolute; cursor:pointer; z-index: 999; right: 16px; top: 22px; color: #fff; font-size: 14px;">
                <el-dropdown style="color:#fff;" trigger="click" @command="handleCommand">
                    <span class="el-dropdown-link">
                      {{Name}}
                      <el-icon class="el-icon--right"><arrow-down></arrow-down></el-icon>
                    </span>
                    <template #dropdown>
                      <el-dropdown-menu>
                        <el-dropdown-item command="changepwd">修改密码</el-dropdown-item>
                        <el-dropdown-item command="logoff">退出登录</el-dropdown-item> 
                      </el-dropdown-menu>
                    </template>
                  </el-dropdown>
            </div>
            <el-menu
                :default-active="activeIndex"
                :popper-offset="0"
                class="el-menu-demo"
                mode="horizontal"
                background-color="#545c64"
                text-color="#fff"
                active-text-color="#ffd04b"
                @select="handleSelect"
              > 
                <template v-for="itemLv1 in TopMenu">
                    <el-sub-menu v-if="itemLv1.children.length>0" :index="itemLv1.ID">
                      <template #title>{{itemLv1.Title}}</template>
                      <template v-for="itemLv2 in itemLv1.children">
                          <el-sub-menu v-if="itemLv2.children&&itemLv2.children.length>0" :index="itemLv2.ID">
                              <template #title>{{itemLv2.Title}}</template>
                              <el-menu-item v-for="itemLv3 in itemLv2.children" :index="itemLv3.ID">{{itemLv3.Title}}</el-menu-item> 
                          </el-sub-menu> 
                          <el-menu-item v-else :index="itemLv2.ID">{{itemLv2.Title}}</el-menu-item> 
                      </template>
                    </el-sub-menu> 
                    <el-menu-item v-else :index="itemLv1.ID">{{itemLv1.Title}}</el-menu-item>
                </template>
              </el-menu>
        </div>
        <div id="MainBody"></div>
    </div>
</body>
</html>
<script>

    /** 页面跳转 */
    function gopage(url, divid) {  
        loaddingPlus(true);
        $.ajax({
            url: url,
            type: 'get',
            success: function (e) {
                $("#" + divid).html(e); 
                loaddingPlus(false);
            }
        })
    }

    var main_app = createApp({
        el: '#mainApp',
        data() {
            return {
                StaticList:[],
                TopMenu: [], 
                activeIndex: '1', 
                Name:"",
                BaseData: null,
                dialogVisible: false,
                pwd: {
                    old: '',
                    new: '',
                    newc:''
                }
            };
        },
        methods: {  
            cgpwd() {
                if (this.pwd.new.length < 6) {
                    MsgBox("密码不能低于6位");
                    return;
                }
                if (this.pwd.new != this.pwd.newc) {
                    MsgBox("两次密码不一致");
                    return;
                }
                var user = new ktluser();
                loaddingPlus(true);
                ktlapi({ 
                    "action": "Cus_UpdataPwd",
                    "data": {
                        ID: user.userInfo().AccountID,
                        oldpwd: this.pwd.old,
                        newpwd: this.pwd.new,
                        repwd: this.pwd.newc
                    }
                }).then(res => {
                    if (res.data[0].status === 1) {
                        this.dialogVisible = false;
                        MsgBox("修改成功"); 
                    } else {
                        MsgBox(res.data[0].msg);  
                    } 
                });
            },
            handleCommand(cmd) {
                if (cmd == 'changepwd') {
                    this.dialogVisible = true;
                } else if (cmd == 'logoff') {
                    var user = new ktluser();
                    user.logoff();
                } 
            },
            handleSelect(key, keyPath) {
                console.log(key, keyPath);
                console.log(this.StaticList)
                var target = "";
                for (var i = 0; i < this.StaticList.length; i++) {
                    if (this.StaticList[i]["ID"] == key) {
                        target = this.StaticList[i]["Target"];
                        if(target == ""){
                            return;
                        }
                        target += "?t=" + Math.random() + "&title=" + this.StaticList[i]["Title"];
                        break;
                    }
                } 
                if (target != "") {
                    gopage(target, 'MainBody'); 
                }
            },

            init() {
                var user = new ktluser();

                var proc = '';
                var isTeacher = false;
                var isAdmin = false;
                if (user.hasRole(1) || user.hasRole(6)) { 
                    proc = 'Cus_GetAdminMenu';
                    isAdmin = true;
                    isTeacher = false;
                }
                else if (user.hasRole(2)) {
                    proc = "Cus_GetTeacherMenu"
                    isAdmin = false;
                    isTeacher = true;
                }

                //console.log(isTeacher);

                loaddingPlus(true);
                ktlapi({
                    "apiurl": OT.CommandSet,
                    "action": proc,
                    "data": {}
                }).then(res => {

                    this.BaseData = res.data.tables[0].table[0]; 

                    var menus = [
                        { "ID": '100', "PID": 0, Role: [1, 6], DLVCenter: false, "Title": "首页", "Target": "/Admin/Main/index.aspx", "children": [] },
                        { "ID": '200', "PID": 0, Role: [1, 6], DLVCenter: false, "Title": "校区管理", "Target": "/Admin/CompanyData/CompanyList.aspx", "children": [] },
                        { "ID": '300', "PID": 0, Role: [1, 6, 2], DLVCenter: true, "Title": "教师管理", "Target": "/Admin/TeacherData/teacherList.aspx", "children": [] },
                        { "ID": '400', "PID": 0, Role: [1, 6, 2], DLVCenter: true, "Title": "学生管理", "Target": "/Admin/StudentData/StudentList.aspx", "children": [] },
                        { "ID": '500', "PID": 0, Role: [1, 6, 2], DLVCenter: true, "Title": "课程中心", "Target": "/Admin/ClassData/ClassCenter.aspx", "children": [] },
                        { "ID": '550', "PID": 0, Role: [1, 6, 2], DLVCenter: true, "Title": "结算中心", "Target": "/Admin/Settle/List.aspx", "children": [] },
                        { "ID": '600', "PID": 0, Role: [1], DLVCenter: false, "Title": "基础数据", "Target": "", "children": [] },
                        { "ID": '6001', "PID": '600', Role: [1], DLVCenter: false, Title: "英语科目", "Target": "", "children": [] },
                        { "ID": '600101', "PID": '6001', Role: [1], DLVCenter: false, Title: "英语词汇维护", "Target": "/Admin/BaseData/WordValid.aspx", "children": [] },
                        { "ID": '600102', "PID": '6001', Role: [1], DLVCenter: false, Title: "英语课程配置", "Target": "/Admin/BaseData/WordConfig.aspx", "children": [] },
                        { "ID": '6002', "PID": '600', Role: [1], DLVCenter: false, Title: "数学科目", "Target": "", "children": [] },
                        { "ID": '600201', "PID": '6002', Role: [1], DLVCenter: false, Title: "数学教材分类", "Target": "/Admin/BaseData/MathConfig/MathLvConfig.aspx", "children": [] },
                        { "ID": '600202', "PID": '6002', Role: [1], DLVCenter: false, Title: "数学教材配置", "Target": "/Admin/BaseData/MathConfig/MathConfig.aspx", "children": [] },
                        { "ID": '700', "PID": 0, Role: [1, 6], DLVCenter: true, "Title": "设置", "Target": "", "children": [] },
                        { "ID": '7001', "PID": '700', Role: [1, 6], DLVCenter: true, Title: "课时费标准", "Target": "/Admin/Setting/Fee.aspx", "children": [] },
                        { "ID": '7002', "PID": '700', Role: [1], Title: "兑换商城", "Target": "/Admin/Setting/Store.aspx", "children": [] },
                        { "ID": '800', "PID": 0, Role: [1], DLVCenter: false, "Title": "商城订单", "Target": "/Admin/Order/List.aspx", "children": [] }
                    ];
                    //
                    if (user.hasRole(1) || user.hasRole(6)) {
                        this.activeIndex = '100';
                        gopage("/Admin/Main/index.aspx", 'MainBody');
                    } else if (user.hasRole(2)) {
                        console.log(this.BaseData);
                        if (this.BaseData) {
                            this.activeIndex = '300';
                            gopage("/Admin/TeacherData/teacherList.aspx", 'MainBody');
                        } else {
                            MsgBox("权限不足");
                            user.logoff();
                            return;
                        }
                    }

                    for (var i = 0; i < menus.length; i++) {
                        for (var j = 0; j < user.userInfo().baseRole.length; j++){
                            var role = user.userInfo().baseRole[j];
                            if (menus[i]["Role"].includes(role.RoleId)) {
                                if (isTeacher) {
                                    if (this.BaseData) {
                                        this.TopMenu.push(menus[i]);
                                    }
                                } else {
                                    if (menus[i]["DLVCenter"]) {
                                        if (this.BaseData["IsDLVCenter"]) {
                                            this.TopMenu.push(menus[i]);
                                        }
                                    } else {
                                        this.TopMenu.push(menus[i]);
                                    }
                                }
                                break;
                            }
                        }
                    }

                    this.StaticList = JSON.parse(JSON.stringify(this.TopMenu));

                    this.TopMenu = treeJson(this.TopMenu, "ID", "PID");
                    //console.log('this.TopMenu', this.TopMenu);
                });   
            }
        },
        mounted: function () {
            var user = new ktluser();
            if (!user.isLogin()) {
                window.location = '/admin/login.html';
            } else {
                this.init();
                this.Name = user.userInfo().Name;
            } 
        }
    });

</script>
